package com.ruoyi.supplier.controller;

import java.util.List;

import com.ruoyi.common.constant.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supplier.domain.TbCheckProductDetail;
import com.ruoyi.supplier.service.ITbCheckProductDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 验货明细Controller
 * 
 * @author ruoyi
 * @date 2021-04-11
 */
@RestController
@RequestMapping("/supplier/checkProductdetail")
public class TbCheckProductDetailController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(TbCheckProductDetailController.class);
    @Autowired
    private ITbCheckProductDetailService tbCheckProductDetailService;

    /**
     * 查询验货明细列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:checkProductdetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCheckProductDetail tbCheckProductDetail)
    {

        startPage();
        List<TbCheckProductDetail> list = tbCheckProductDetailService.selectTbCheckProductDetailList(tbCheckProductDetail);
        return getDataTable(list);
    }

    /**
     * 导出验货明细列表
     */
    @PreAuthorize("@ss.hasPermi('supplier:checkProductdetail:export')")
    @Log(title = "验货明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbCheckProductDetail tbCheckProductDetail)
    {
        List<TbCheckProductDetail> list = tbCheckProductDetailService.selectTbCheckProductDetailList(tbCheckProductDetail);
        ExcelUtil<TbCheckProductDetail> util = new ExcelUtil<TbCheckProductDetail>(TbCheckProductDetail.class);
        return util.exportExcel(list, "checkProductdetail");
    }

    /**
     * 获取验货明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('supplier:checkProductdetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbCheckProductDetailService.selectTbCheckProductDetailById(id));
    }

    /**
     * 新增验货明细
     */
    @PreAuthorize("@ss.hasPermi('supplier:checkProductdetail:add')")
    @Log(title = "验货明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCheckProductDetail tbCheckProductDetail)
    {
        return toAjax(tbCheckProductDetailService.insertTbCheckProductDetail(tbCheckProductDetail));
    }

    /**
     * 修改验货明细
     */
    @PreAuthorize("@ss.hasPermi('supplier:checkProductdetail:edit')")
    @Log(title = "验货明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCheckProductDetail tbCheckProductDetail)
    {
        int i = tbCheckProductDetailService.updateTbCheckProductDetail(tbCheckProductDetail);
        if(i==-1){
            return new AjaxResult(HttpStatus.SUCCESS, "此采购明细已经完成全部验货，不能在进行验货，请重新选择", -1);
        }

        return toAjax(i);
    }

    /**
     * 删除验货明细
     */
    @PreAuthorize("@ss.hasPermi('supplier:checkProductdetail:remove')")
    @Log(title = "验货明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        int i =tbCheckProductDetailService.deleteTbCheckProductDetailByIds(ids);
        if(i==-1) {
            return new AjaxResult(HttpStatus.SUCCESS, "包含已提交数据，不能删除", -1);
        }
        return toAjax(i);
    }
}
